package com.zzzzzz.taglib.ui;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.zzzzzz.common.util.Validator;
import com.zzzzzz.core.servlet.IncludeUtil;

public class MessageTag extends TagSupport {

	@Override
	public int doEndTag() throws JspException {
		try{
			String page = getPage();
			
			if (Validator.isNotNull(page)) {
				IncludeUtil.include(pageContext, page);
			}
			
			return EVAL_PAGE;
			
		}catch (Exception e) {
			throw new JspException(e);
		}
	}

	@Override
	public int doStartTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		request.setAttribute("zzzzzz-ui:message:key", _key);
		request.setAttribute("zzzzzz-ui:message:type", _type);
		return SKIP_BODY;
	}
	
	protected String getPage() {
		return _PAGE;
	}

	public void setKey(String key) {
		_key = key;
	}

	public void setType(String type) {
		_type = type;
	}
	
	private static final String _PAGE = "/taglib/ui/message/page.jsp";

	private String _key;
	
	private String _type;
}
